<?php
/**
 * @author Administrator
 * @date 2022/9/26 19:41
 * @desciption:
 */

namespace Plugins;


abstract class Application
{
    public static $version;
    public static $enable;
    public static $app_name;
    public static $app_path = "plugins";

    public static function getAppName(){
        return self::$app_name;
    }

    public static function getVersion(){
        return self::$version;
    }

    public static function getStatus(){
        return self::$enable;
    }

    /**
     * @param $app
     * 基类提供基础注册路由、注册事件、注册字段
     * 子类也可以覆盖
     */
    public static function boot($app){
        static::registerConfig($app);
        static::registerRoute($app->router);
        static::registerEvent();
        static::registerField();
    }

    /**
     * @param $router
     * 注入路由
     */
    public static function registerRoute($router){
        $router->group(
            array_merge(static::buildControllerNamespace(),static::getRoutePrefix()),
            function($router){
                static::defineRoute($router);
            }
        );
    }

    /**
     * @return array
     * 定义控制器命名空间
     */
    public static function buildControllerNamespace(){
        return [
            "namespace" =>  str_replace("Application","",get_called_class()) . "Controllers"
        ];
    }

    /**
     * @return array
     * 定义路由前缀
     */
    public static function getRoutePrefix(){
        return ["prefix" => "/app"];
    }

    /**
     * @param $router
     * 定义路由
     */
    public static function defineRoute($router){}

    /**
     * 注入事件
     */
    public static function registerEvent(){}

    /**
     * GraphQL字典的注入
     */
    public static function registerField(){}

    /**
     * @param $app
     * 注入配置文件
     */
    public static function registerConfig($app){}

}